﻿// (c) Copyright 2013 Mike Riedel.
// This source is subject to the Microsoft Public License (Ms-PL).
// All other rights reserved.

using System;

namespace FreshMeat.Storage
{
   /// <summary>
   /// Respository that stores its data in the file system.
   /// </summary>
   /// <typeparam name="TId">Type of ID that uniquely identifies each item.</typeparam>
   /// <typeparam name="TItem">Type of item to be stored.</typeparam>
   public class FileRepository<TId, TItem> : Repository<TId, TItem, TItem>
   {
      /// <summary>
      /// Creates instance using file system and serializer.
      /// </summary>
      /// <param name="idGetter">Function which gets an item's ID.</param>
      /// <param name="fileSystem">File system to use.</param>
      /// <param name="serializer">Serializer to use.</param>
      public FileRepository(Func<TItem, TId> idGetter, IFileSystem fileSystem, ISerializer<TItem> serializer)
         : base(new IdentityMapper<TId, TItem>(idGetter), new FileStore<TId, TItem>(fileSystem, serializer))
      {
      }

      /// <summary>
      /// Creates instance using file locator and serializer.
      /// </summary>
      /// <param name="idGetter">Function which gets an item's ID.</param>
      /// <param name="fileLocator">File locator to use.</param>
      /// <param name="serializer">Serializer to use.</param>
      public FileRepository(Func<TItem, TId> idGetter, FileLocator<TId> fileLocator, ISerializer<TItem> serializer)
         : base(new IdentityMapper<TId, TItem>(idGetter), new FileStore<TId, TItem>(fileLocator, serializer))
      {
      }
   }
}